﻿using dotnet_etcd;


EtcdClient client = new EtcdClient("https://localhost:2379,https://localhost:2380");

#region ===================== 授权访问 =====================
var auth = client.Authenticate(new Etcdserverpb.AuthenticateRequest()
{
    Name = "admin",
    Password = "123456",
});

client.Put("users/u1001", "this is u1001", new Grpc.Core.Metadata() {
        new Grpc.Core.Metadata.Entry("token",auth.Token)
    });
#endregion

#region ====================== Put操作 ======================
client.Put("users/u1002", "this is u1002");
await client.PutAsync("users/u1003", "this is u1003");
#endregion

#region ====================== Get操作 ======================
Console.WriteLine(client.GetVal("users/u1002"));  //获取值
Console.WriteLine(client.Get("users/u1003"));     //获取完整对象
Console.WriteLine();

Console.WriteLine(await client.GetValAsync("users/u1002")); //获取值
Console.WriteLine(await client.GetAsync("users/u1003"));    //获取完整对象
#endregion

#region ======================Range操作======================
// 前缀模式匹配
Console.WriteLine(client.GetRange("users/"));
//Console.WriteLine(await client.GetRangeAsync("users/"));
//await client.GetRangeAsync("users/");
Console.WriteLine();

// 获取所有对象
Console.WriteLine(await client.GetRangeAsync(""));
#endregion

#region ==================== Delete操作 ====================
client.Delete("foo/bar"); 
await client.DeleteAsync("foo/bar");

client.DeleteRange("foo/");
await client.DeleteRangeAsync("foo/");
#endregion

#region ====================== Watch 操作 ======================

#endregion

#region ====================== 集群操作 ======================

#endregion


Console.ReadKey();